package com.ruoyi.food.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.food.object.TActOrder;
import com.ruoyi.food.object.TCancelVerification;

/**
 * 核销mapper
 * @author Administrator
 *
 */
@Mapper
public interface TCancelVerificationMapper extends BaseMapper<TActOrder>{
	public static final String sql="SELECT c.NAME,c.MOBILE,c.HX_TYPE,c.HX_TIME,c.POS_NO,c.TERM_NO,e.NAME as ename,a.ACT_NAME, e.STOCK_NUM "
			                       + "from (t_cancel_verification c LEFT JOIN t_enterprise e on c.ENTERPRISE_ID=e.ENTERPRISE_ID) LEFT JOIN t_activity a on c.ACT_ID=a.ACT_ID";
	
	@Select({"<script>",
        sql,
        "WHERE 1=1",
        "<when test='name != \"\" and name !=null'>",
        "AND c.NAME like concat('%', #{name}, '%')",
        "</when>",
        "<when test='ename != \"\" and ename !=null'>",
        "AND e.NAME like concat('%', #{ename}, '%')",
        "</when>",
        "<when test='params.beginTime != \"\" and params.beginTime !=null'>",
        "AND date_format(c.HX_TIME,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')",
        "</when>",
        "<when test='params.endTime != \"\" and params.endTime !=null'>",
        "AND date_format(c.HX_TIME,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')",
        "</when>",
        "</script>"})
	public List<TCancelVerification> selectCanceByCon(TCancelVerification tCancelVerification);
	
	@Insert("insert into t_cancel_verification(ENTERPRISE_ID,ACT_ID,USER_ID,NAME,MOBILE,HX_TYPE,HX_TIME,POS_NO,TERM_NO,LONGITUDE,LATITUDE) "
			+ "VALUES(#{enterpriseId},#{actId},#{userId},#{name},#{mobile},#{hxType},#{hxTime},#{posNo},#{termNo},#{longitude},#{latitude})")
	public void insertTCancelVer(TCancelVerification tCancelVerification);
	
	/**
	 * 查询核销列表(包含库存数)
	 * @return
	 */
	//@Select("select e.STOCK_NUM,c.* from t_cancel_verification c,t_enterprise e where c.ENTERPRISE_ID=e.ENTERPRISE_ID")	
	@Select({"<script>",
        "select e.STOCK_NUM,e.NAME as ename,a.ACT_NAME,c.* from t_cancel_verification c,t_enterprise e,t_activity a where c.ENTERPRISE_ID=e.ENTERPRISE_ID and c.ACT_ID=a.ACT_ID",
        "<when test='string != \"\" and string !=null'>",
        "AND (e.NAME like concat('%', #{string}, '%') or c.name like concat('%', #{string}, '%') or c.MOBILE like concat('%', #{string}, '%'))",
        "</when>",
        "</script>"})
	public List<TCancelVerification> selectListAndNum(@Param("string")String string);

}
